package com.picturehistory.core.jersey.test;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@Service
public class EmployeeService {
	@Autowired
	private EmployeeDAO dao;
	
	public EmployeeService() {}
	public EmployeeService(EmployeeDAO dao) {
		this.dao = dao;
	}
	
	public void simpleCreate(String title, String first, String last) {
		dao.simpleCreate(title, first, last);
	}
	
	public Employee simpleRead(String first, String last) {
		return dao.simpleRead(first, last);
	}
	
	public void store(String title, String first, String last) {
		try {
			Employee employee = new Employee(title, first, last, new Date());
			Key key = KeyFactory.createKey(Employee.class.getSimpleName(), first+last);
			employee.setKey(key);
			dao.store(employee);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public Employee load(String firstName, String lastName) {
		Employee ret = null;
		try {
			ret = dao.load(firstName, lastName);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ret;
	}
}
